
// Source File Name:   UIDImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;
import com.sunwayhorizo.health.hl7.datatypes.UID;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.OIDParser;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.OIDParserConstants;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.ParseException;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.Token;

//            STCommonImpl, ANYImpl, BLImpl, CSImpl,
//            TYPEImpl

public class UIDImpl extends STCommonImpl
    implements UID
{

    public static final String RCS_ID = "$Header: UIDImpl.java 1.0 2006/09/16 10:39:35 mmoores noship $";
    private static final UID nullNI = new UIDImpl(CSImpl.valueOf("NI"));
    private static final UID nullOTH = new UIDImpl(CSImpl.valueOf("OTH"));
    private static final UID nullNINF = new UIDImpl(CSImpl.valueOf("NINF"));
    private static final UID nullPINF = new UIDImpl(CSImpl.valueOf("PINF"));
    private static final UID nullUNK = new UIDImpl(CSImpl.valueOf("UNK"));
    private static final UID nullASKU = new UIDImpl(CSImpl.valueOf("ASKU"));
    private static final UID nullNAV = new UIDImpl(CSImpl.valueOf("NAV"));
    private static final UID nullMSK = new UIDImpl(CSImpl.valueOf("MSK"));
    private static final UID nullNA = new UIDImpl(CSImpl.valueOf("NA"));
    private static final UID nullNASK = new UIDImpl(CSImpl.valueOf("NASK"));

    public static UID valueOf(String s)
    {
        if(s == null || s.length() == 0)
            return nullUID(null);
        else
            return new UIDImpl(s);
    }

    protected UIDImpl(String s)
    {
        super(s);
    }

    protected UIDImpl(CS cs)
    {
        super(cs);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.UID;
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof UID))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            UID uid = (UID)any;
            return BLImpl.valueOf(stringValue().equals(uid.stringValue()));
        }
    }

    public static void checkParserState(OIDParser oidparser)
        throws ParseException
    {
        Token token = oidparser.token;
        if(token.next == null)
            token.next = oidparser.token_source.getNextToken();
        if(token.next.kind != 0)
            throw new ParseException(token, new int[0][0], OIDParserConstants.tokenImage);
        else
            return;
    }

    public static UID nullUID(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

	public byte[] byteArray() {
		// TODO Auto-generated method stub
		return null;
	}

}
